Fix plaintext length check for UTF-8 strings#193
Draft
toddr-bot wants to merge 1 commit into
Draft
Conversation
check_max_message_length() used sv_len() which returns character count for UTF-8 SVs, but rsa_crypt() passes the raw bytes to OpenSSL via SvPV(). For multi-byte UTF-8 strings the byte count exceeds the character count, so the pre-validation could pass while OpenSSL rejects the oversized input with a generic error instead of our descriptive "plaintext too long" message. Switch check_max_message_length() to accept the SV directly and extract byte length via SvPV(), matching what rsa_crypt() actually sends to OpenSSL. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Use byte length instead of character length in
check_max_message_length().Why
sv_len()returns character count for UTF-8-flagged SVs, butrsa_crypt()passes raw bytes to OpenSSL viaSvPV(). When a UTF-8 string has multi-byte characters, the byte count exceeds the character count — so the pre-validation could pass while OpenSSL rejects the oversized input with a generic error instead of the descriptive "plaintext too long" message.How
Changed
check_max_message_length()to acceptSV*directly and extract byte length viaSvPV(), matching whatrsa_crypt()actually sends to OpenSSL. Bothencrypt()andprivate_encrypt()callers updated.Testing
t/crypto.t: constructs a UTF-8 string where character count (120) < OAEP max (214) but byte count (240) > OAEP max, verifying the descriptive error fires.🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 26 insertions(+), 4 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline